<!--
 * 患者住院列表
 *
-->
<template>
  <div>
    <el-card>
      <!-- 搜索栏 -->
      <el-row type="flex">
        <el-col :span="8">
          <el-input v-model="query" placeholder="请输入手术id查询">
            <el-button
                slot="append"
                icon="iconfont icon-search-button"
                @click="requestSurgery"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table size="small" :data="OperationData" stripe border>
        <el-table-column label="手术序号" prop="sId"/>
        <el-table-column label="手术名称" prop="sName"/>
        <el-table-column label="手术原因" prop="sReason"/>
        <el-table-column label="费用"  prop="sMoney"/>
        <el-table-column label="手术时间" prop="sDate"/>
        <el-table-column label="是否支付" prop="sPay">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.sPay === 1" type="primary"
            >已支付
            </el-tag>
            <el-tag v-if="scope.row.sPay === 0" type="danger"
            >未支付
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template slot-scope="scope">
            <el-button
                size="small"
                style="font-size: 14px"
                type="danger"
                @click="deleteDialog(scope.row.sId)"
            ><i class="iconfont icon-delete-button" style="font-size: 12px;"></i></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="pageNumber"
          :page-size="size"
          :page-sizes="[1, 2, 4, 8, 16]"
          :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import jwtDecode from "jwt-decode";
import { getToken } from "@/utils/storage.js";
import request from "@/utils/request.js";
export default {
  name: "OperationList",
  data() {
    return {
      userId: 1,
      userName: "",
      pageNumber: 1,
      size: 4,
      query: "",
      total: 3,
      OperationData: [],
      //申请住院对话框
      BedFormVisible: false,
      OperationForm: {},
      nullOperation: [],
    };
  },
  methods: {
    //点击申请床位确认按钮
    bedClick() {
      request
          .get("bed/updateBed", {
            params: {
              bId: this.bedForm.bId,
              dId: this.bedForm.dId,
              pId: this.bedForm.pId,
              bReason: this.bedForm.bReason,
            },
          })
          .then((res) => {
            if (res.data.status !== 200)
              return this.$message.error("来晚了...该床位已被占用");
            this.BedFormVisible = false;
            this.$message.success("申请住院成功！");
            this.requestOrders();
          });
    },

    //请求所有空床位
    requestBeds() {
      request
          .get("bed/findNullBed")
          .then((res) => {
            if (res.data.status !== 200)
              return this.$message.error("数据请求失败");
            this.nullBed = res.data.data;
          })
          .catch((err) => {
          });
    },
    //打开申请住院对话框
    BedDiag(pId, dId) {
      this.bedForm.pId = pId;
      this.bedForm.dId = dId;
      this.BedFormVisible = true;
      this.requestBeds();
    },
    //页面大小改变时触发
    handleSizeChange(size) {
      this.size = size;
      this.requestOrders();
    },
    //页码改变时触发
    handleCurrentChange(num) {
      this.pageNumber = num;
      this.requestOrders();
    },
    //删除药物操作
    deleteSurgery(id) {
      request
          .get("surgery/deleteSurgery", {
            params: {
              sId: id,
            },
          })
          .then((res) => {
            this.requestDrugs();
          });
    },
    //删除对话框
    deleteDialog(id) {
      this.$confirm("此操作将删除该手术信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
          .then(() => {
            this.deleteSurgery(id);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
    },
    //查询手术
    requestSurgery() {
      request
          .get("surgery/findAllSurgery", {
            params: {
              pageNumber: this.pageNumber,
              size: this.size,
              query: this.query,
            },
          })
          .then((res) => {
            if (res.data.status !== 200)
              return this.$message.error("数据请求失败");
            this.OperationData = res.data.data.surgerys;
            this.total = res.data.data.total;
          });
    },
    //token解码
    tokenDecode(token) {
      if (token !== null) return jwtDecode(token);
    },
  },
  created() {

    this.requestSurgery();
  },
};
</script>
<style lang="scss" scoped>
.el-table {
  margin-top: 20px;
  margin-bottom: 20px;
}
</style>
